<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>我的课销记录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/main.css">
    <link rel="stylesheet" href="./css/head.css">
    <link rel="stylesheet" href="../css/window.css">
    <link rel="stylesheet" href="./css/signin_apply_student.css">
    <style scoped>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div style="height: 40px;"></div>
    <div class="header">
        <div class="header_title">我的课销记录</div>
        <img src="../image/return.png" alt="" class="return" onclick="history.back()">
    </div>
    <div class="apply" id="vue-root" v-cloak>
        <div class="content_box">
            <div class="content_box_head">
                <div class="content_box_head_item" @click="mask=true">课销记录</div>
                <div class="content_box_head_item content_box_head_item2">
                    <img src="../image/img/buqian_icon.png" alt="">
                    <span>补签</span>
                </div>
            </div>
            <div id="calendar"></div>
            <div class="keshi">本月课销总数量：共<span>{{ attendanceCount }}</span>天</div>
            <div class="zhushi">注：蓝色为已课销.</div>
            <div class="mask_layer" v-if="mask">
                <div class="mask_item">
                    <div class="mask_item_title">课销记录</div>
                    <div class="date_input">
                        <input type="date" placeholder="请选择日期" v-model="form.birthday">
                    </div>
                    <div class="mask_item_content">
                        <div class="mask_item_content_item">
                            <div class="mask_item_content_item_title">语文课</div>
                            <div class="mask_item_content_item_text">
                                状态<span class="text_span">正常签到</span>
                            </div>
                            <div class="mask_item_content_item_text">
                                课销时间<span style="margin-left: 10px;">08:30</span>
                            </div>
                        </div>
                        <div class="mask_item_content_item">
                            <div class="mask_item_content_item_title">语文课</div>
                            <div class="mask_item_content_item_text">
                                状态<span class="text_span text_span2">补签</span>
                            </div>
                            <div class="mask_item_content_item_text">
                                课销时间<span style="margin-left: 10px;">08:30</span>
                            </div>
                        </div>
                    </div>
                    <div class="cancel" @click="mask=false"></div>
                </div>
            </div>
        </div>
    </div>

    <script src="/scriptZIP/qs.min.js"></script>
    <script src="/scriptZIP/vue.min.js"></script>
    <script src="/scriptZIP/axios.min.js"></script>
    <script src="/scriptZIP/dayjs.min.js"></script>

    <script src="/js/common.js"></script>
    <script src="/lib/laydate/laydate.js"></script>

    <script>
        var app = new Vue({
            el: '#vue-root',
            data: {
                studentId: params().id,
                form: { time: dayjs().format('YYYY-MM-DDTHH:mm'), birthday: dayjs().format('YYYY-MM-DD'), class: 1 },
                year: new Date().getFullYear(),
                month: new Date().getMonth() + 1,
                list: [],
                mask: false,
                attendanceCount: 0,
               
            },
            created: function () {
                this.getData();
            },
            methods: {
                getData: function () {
                    var month = this.year + '-' + this.month;
                    if (dayjs(month + '-1').isAfter(dayjs())) return;
                    
                    axios.get('/api/attendanceRecord/student/'+this.studentId, { params: { month: month } })
                        .then(function (response) {
                            var list = response.data;
                            var mark = {};
                            var o = {};
                            list.forEach(function (it) {
                                o[it] = it;
                                mark[month + '-' + it] = '';
                            });

                            reload(month + '-1', mark);
                            this.list = Object.keys(o);
                            this.attendanceCount = list.length;
                        }.bind(this))
                        .catch(function (error) {
                            console.error('Error fetching attendance records:', error);
                        });
                },
                dayclick(date) {
                    console.log(date);
                }
            }
        });

        function reload(value, mark) {
            var done = false;
            var div = document.getElementById('layui-laydate1');
            if (div) div.parentNode.removeChild(div);

            laydate.render({
                elem: '#calendar',
                mark: mark,
                showBottom: false,
                position: 'static',
                value: value,
                change: function (value, date) {
                    var date = dayjs(value);

                    if (done) {
                        done = false;
                        app.dayclick(date.date());
                        return;
                    }

                    app.year = date.year();
                    app.month = date.month() + 1;
                    app.getData();
                },
                done: function (value, date, endDate) {
                    done = true;
                }
            });
        }
    </script>

</body>

</html>
